#include "Player.h"
#include "Factory.h"
#include "File.h"
#include "DX11ErrorReport.h"
#include "ObjMeshManager.h"
#include "AntTweakBarManager.h"
#include "LightingManager.h"

Player::Player()
{
	//m_addVel = true;
	//m_vel = 0.001f;
	m_collided = false;
	//m_rbSquare.SetForce(XMVectorSet(0.0f, 10.0f, 0.0f, 1.0f));
}

void Player::Draw()
{	
	//m_rbSquare->Draw();

	//static float rotAngle = 0.0f;

	//m_oobb3.Rotate(DegToRad(rotAngle), Vec3f(0, 1, 1));
	//m_oobb3.centre.x = XMVectorGetX(m_rbSquare->GetPosition());
	//m_oobb3.centre.y = XMVectorGetY(m_rbSquare->GetPosition());
	//m_oobb3.centre.z = XMVectorGetZ(m_rbSquare->GetPosition());

	//if (m_collided)
	//{
	//	TheObjMeshManager::Instance()->SetColour("crate_textured", D3DXVECTOR4(0.5f, 0.0f, 0.0f, 1.0f));
	//}
	//else
	//{
	//	TheObjMeshManager::Instance()->SetColour("crate_textured", D3DXVECTOR4(1.0f, 1.0f, 1.0f, 1.0f));
	//}

	//TheObjMeshManager::Instance()->Translate("crate_textured", m_rbSquare->GetPosition());
	//TheObjMeshManager::Instance()->Rotate("crate_textured", DegToRad(rotAngle), 0, 1, 1);
	//TheObjMeshManager::Instance()->Scale("crate_textured", m_oobb3.extents[0] * 2, m_oobb3.extents[0] * 2, m_oobb3.extents[0] * 2);
	//TheObjMeshManager::Instance()->Draw("crate_textured");
	//m_size = 1;
	//m_collided = false;	
	
	TheObjMeshManager::Instance()->Translate("crate_textured", m_pos);
	TheObjMeshManager::Instance()->Rotate("crate_textured", DegToRad(0), 0, 1, 1);
	TheObjMeshManager::Instance()->Scale("crate_textured", m_oobb3.extents[0] * 2, m_oobb3.extents[0] * 2, m_oobb3.extents[0] * 2);
	TheObjMeshManager::Instance()->Draw("crate_textured");
}

void Player::Update()
{

}

void Player::StopAddingVel()
{
	m_collided = true;
	//m_size = 4;
}

bool Player::Load(File* f)
{
	if (!f->GetD3DXVECTOR3(&m_pos))
	{
		DX11ErrorMsg(L"Expected position", L"Player load function error", MB_YESNO);
	}

	if (!f->GetOOBB3(&m_oobb3))
	{
		DX11ErrorMsg(L"Expected oobb2", L"Player load function error", MB_YESNO);
	}
	return true;
}

// load player as game object functions
GameObject* CreatePlayer()
{
	return new Player();
}

static bool b = TheGameObjectFactory::Instance()->AddType("Player", CreatePlayer);

const char* Player::GetTypeName() const
{
	return "Player";
}